let defaultActive=localStorage.getItem('defaultActive')
let activeList=localStorage.getItem('activeList')
if(activeList)activeList=JSON.parse(activeList)
if(!activeList)activeList=[]
import variables from '@/styles/share.scss'
export default {
  namespaced: true,//开启命名空间
  state: { 
    tabList:[], // 测导航列表
    defaultActive,// 当前选中导航,用于控制侧导航
    activeList,// 顶部小导航,当前已经看过的页面
    theme:variables.theme
   },
  mutations: {
    changeTabs(state,data){
      state.tabList=data
    },
    changedefaultActive(state,[path,name]){
      state.defaultActive=path
      localStorage.setItem('defaultActive',path)
      function fun(){
        for (const item of state.activeList) {
          if(item.path==path){
            return true
            break;
          }
        }
        return false
      }
      if(!fun()){
        state.activeList.push({
          path,
          name
        })
        localStorage.setItem('activeList',JSON.stringify(state.activeList))
      }
    },
    updateTopTab(state,[activeList,defaultActive]){
      state.activeList=activeList
      // state.defaultActive=defaultActive
      localStorage.setItem('activeList',JSON.stringify(activeList))
    },
    SET_THEME(state,val){
      state.theme=val
      localStorage.setItem('theme',val)
    }
  },
  actions: { },
  getters: {
    getTabsList:state=>state.tabList,
    gettheme:state=>state.theme
  }
}